home *** CD-ROM | disk | FTP | other *** search
- function buildMap(map)
- {
- function enemyBrain()
- {
- var i = 0;
- while(i < 5)
- {
- var name = "enemy" + i;
- var ob = game[name];
- getMyCorners(ob.x + ob.speed * ob.xMove,ob.y + ob.speed * ob.yMove,ob);
- if(ob.downleft and ob.upleft and ob.downright and ob.upleft)
- {
- moveChar(ob,ob.xMove,ob.yMove);
- }
- else
- {
- ob.xMove = - ob.xMove;
- ob.yMove = - ob.yMove;
- }
- if(!_root.infiniteLife)
- {
- var xdist = ob.x - char.x;
- var ydist = ob.y - char.y;
- if(math.sqrt(xdist * xdist + ydist * ydist) < ob.width + char.width)
- {
- _root.lifes -= 1;
- mylifes.gotoAndStop(_root.lifes);
- if(_root.lifes == 0)
- {
- removeMovieClip(_root.tiles);
- _root.gotoAndStop(35);
- }
- if(!_root.hurt)
- {
- char.clip.gotoAndPlay("hurt");
- return undefined;
- }
- }
- }
- i++;
- }
- }
- function detectKeys()
- {
- var ob = _root.char;
- var keypressed = false;
- if(key.isDown(39))
- {
- keyPressed = _root.moveChar(ob,1,0);
- }
- else if(key.isDown(37))
- {
- keyPressed = _root.moveChar(ob,-1,0);
- }
- else if(key.isDown(38))
- {
- keyPressed = _root.moveChar(ob,0,-1);
- }
- else if(key.isDown(40))
- {
- keyPressed = _root.moveChar(ob,0,1);
- }
- if(!KeyPressed)
- {
- ob.clip.mychar.gotoAndStop(1);
- }
- else
- {
- ob.clip.mychar.play();
- }
- enemyBrain();
- }
- function moveChar(ob, dirx, diry)
- {
- getMyCorners(ob.x,ob.y + ob.speed * diry,ob);
- if(diry == -1)
- {
- if(ob.upleft and ob.upright)
- {
- ob.y += ob.speed * diry;
- }
- else
- {
- ob.y = ob.ytile * game.tileH + ob.height;
- }
- }
- if(diry == 1)
- {
- if(ob.downleft and ob.downright)
- {
- ob.y += ob.speed * diry;
- }
- else
- {
- ob.y = (ob.ytile + 1) * game.tileH - ob.height;
- }
- }
- getMyCorners(ob.x + ob.speed * dirx,ob.y,ob);
- if(dirx == -1)
- {
- if(ob.downleft and ob.upleft)
- {
- ob.x += ob.speed * dirx;
- }
- else
- {
- ob.x = ob.xtile * game.tileW + ob.width;
- }
- }
- if(dirx == 1)
- {
- if(ob.upright and ob.downright)
- {
- ob.x += ob.speed * dirx;
- }
- else
- {
- ob.x = (ob.xtile + 1) * game.tileW - ob.width;
- }
- }
- ob.clip._x = ob.x;
- ob.clip._y = ob.y;
- ob.clip.gotoAndStop(dirx + diry * 2 + 3);
- ob.xtile = Math.floor(ob.clip._x / game.tileW);
- ob.ytile = Math.floor(ob.clip._y / game.tileH);
- var itemname = game["item" + ob.ytile + "_" + ob.xtile];
- if(itemname and ob == _root.char)
- {
- game.points = true;
- removeMovieClip(itemname.clip);
- game.items[itemname.position] = 0;
- delete game["item" + ob.ytile + "_" + ob.xtile];
- var name = "enemy3";
- game[name] = new game.Enemyp3();
- game.clip.attachMovie("enemy1",name,10005);
- game[name].clip = game.clip[name];
- game[name].xtile = 4;
- game[name].ytile = 2;
- game[name].width = game.clip[name]._width / 2;
- game[name].height = game.clip[name]._height / 2;
- game[name].x = game[name].xtile * game.tileW + game.tileW / 2;
- game[name].y = game[name].ytile * game.tileH + game.tileH / 2;
- game[name].clip._x = game[name].x;
- game[name].clip._y = game[name].y;
- if(game.points = true)
- {
- opendoorname = "t_" + unlockY + "_" + unlockX;
- game.clip[opendoorname].gotoAndStop(4);
- game.Tile2.prototype.walkable = true;
- }
- }
- if(_root.char.ytile == unlockY && _root.char.xtile == unlockX)
- {
- removeMovieClip(_root.tiles);
- _root.gotoAndStop(11);
- }
- if(_root.char.ytile == 4 && _root.char.xtile == 4)
- {
- var name = "enemy3";
- game[name].xMove = 0;
- game[name].yMove = -1;
- game[name].speed = 0.5;
- }
- return true;
- }
- function getMyCorners(x, y, ob)
- {
- ob.downY = Math.floor((y + ob.height - 1) / game.tileH);
- ob.upY = Math.floor((y - ob.height) / game.tileH);
- ob.leftX = Math.floor((x - ob.width) / game.tileW);
- ob.rightX = Math.floor((x + ob.width - 1) / game.tileW);
- ob.upleft = game["t_" + ob.upY + "_" + ob.leftX].walkable;
- ob.downleft = game["t_" + ob.downY + "_" + ob.leftX].walkable;
- ob.upright = game["t_" + ob.upY + "_" + ob.rightX].walkable;
- ob.downright = game["t_" + ob.downY + "_" + ob.rightX].walkable;
- }
- _root.attachMovie("empty","tiles",++d);
- game.clip = _root.tiles;
- game.clip._x = gameInitial_x;
- game.clip._y = gameInitial_y;
- var mapWidth = map[0].length;
- var mapHeight = map.length;
- var i = 0;
- while(i < mapHeight)
- {
- var j = 0;
- while(j < mapWidth)
- {
- var name = "t_" + i + "_" + j;
- game[name] = new game["Tile" + map[i][j]]();
- game.clip.attachMovie("tile",name,i * 100 + j * 2);
- game.clip[name]._x = j * game.tileW;
- game.clip[name]._y = i * game.tileH;
- game.clip[name].gotoAndStop(game[name].frame);
- j++;
- }
- i++;
- }
- game.items = myItems;
- var i = 0;
- while(i < game.items.length)
- {
- var name = "item" + game.items[i][2] + "_" + game.items[i][1];
- game[name] = new game["Item" + game.items[i][0]]();
- game[name].position = i;
- game.clip.attachMovie("item",name,10001 + i);
- game[name].clip = game.clip[name];
- game[name].clip._x = game.items[i][1] * game.tileW + game.tileW / 2;
- game[name].clip._y = game.items[i][2] * game.tileH + game.tileH / 2;
- game[name].clip.gotoAndStop(game.items[i][0]);
- i++;
- }
- var enemies = myEnemies;
- game.currentEnemies = enemies.length;
- var i = 0;
- while(i < game.currentEnemies)
- {
- var name = "enemy" + i;
- game[name] = new game["Enemyp" + enemies[i][0]]();
- game.clip.attachMovie("enemy1",name,10021 + i);
- game[name].clip = game.clip[name];
- game[name].xtile = enemies[i][1];
- game[name].ytile = enemies[i][2];
- game[name].width = game.clip[name]._width / 2;
- game[name].height = game.clip[name]._height / 2;
- game[name].x = game[name].xtile * game.tileW + game.tileW / 2;
- game[name].y = game[name].ytile * game.tileH + game.tileH / 2;
- game[name].clip._x = game[name].x;
- game[name].clip._y = game[name].y;
- i++;
- }
- game.clip.attachMovie("char","char",1000);
- char.clip = game.clip.char;
- char.x = char.xtile * game.tileW + game.tileW / 2;
- char.y = char.ytile * game.tileH + game.tileH / 2;
- char.width = char.clip._width / 2;
- char.height = char.clip._height / 2;
- char.clip._x = char.x;
- char.clip._y = char.y;
- }
- function enemyBrain()
- {
- var i = 0;
- while(i < 5)
- {
- var name = "enemy" + i;
- var ob = game[name];
- getMyCorners(ob.x + ob.speed * ob.xMove,ob.y + ob.speed * ob.yMove,ob);
- if(ob.downleft and ob.upleft and ob.downright and ob.upleft)
- {
- moveChar(ob,ob.xMove,ob.yMove);
- }
- else
- {
- ob.xMove = - ob.xMove;
- ob.yMove = - ob.yMove;
- }
- if(!_root.infiniteLife)
- {
- var xdist = ob.x - char.x;
- var ydist = ob.y - char.y;
- if(math.sqrt(xdist * xdist + ydist * ydist) < ob.width + char.width)
- {
- _root.lifes -= 1;
- mylifes.gotoAndStop(_root.lifes);
- if(_root.lifes == 0)
- {
- removeMovieClip(_root.tiles);
- _root.gotoAndStop(35);
- }
- if(!_root.hurt)
- {
- char.clip.gotoAndPlay("hurt");
- return undefined;
- }
- }
- }
- i++;
- }
- }
- function detectKeys()
- {
- var ob = _root.char;
- var keypressed = false;
- if(key.isDown(39))
- {
- keyPressed = _root.moveChar(ob,1,0);
- }
- else if(key.isDown(37))
- {
- keyPressed = _root.moveChar(ob,-1,0);
- }
- else if(key.isDown(38))
- {
- keyPressed = _root.moveChar(ob,0,-1);
- }
- else if(key.isDown(40))
- {
- keyPressed = _root.moveChar(ob,0,1);
- }
- if(!KeyPressed)
- {
- ob.clip.mychar.gotoAndStop(1);
- }
- else
- {
- ob.clip.mychar.play();
- }
- enemyBrain();
- }
- function moveChar(ob, dirx, diry)
- {
- getMyCorners(ob.x,ob.y + ob.speed * diry,ob);
- if(diry == -1)
- {
- if(ob.upleft and ob.upright)
- {
- ob.y += ob.speed * diry;
- }
- else
- {
- ob.y = ob.ytile * game.tileH + ob.height;
- }
- }
- if(diry == 1)
- {
- if(ob.downleft and ob.downright)
- {
- ob.y += ob.speed * diry;
- }
- else
- {
- ob.y = (ob.ytile + 1) * game.tileH - ob.height;
- }
- }
- getMyCorners(ob.x + ob.speed * dirx,ob.y,ob);
- if(dirx == -1)
- {
- if(ob.downleft and ob.upleft)
- {
- ob.x += ob.speed * dirx;
- }
- else
- {
- ob.x = ob.xtile * game.tileW + ob.width;
- }
- }
- if(dirx == 1)
- {
- if(ob.upright and ob.downright)
- {
- ob.x += ob.speed * dirx;
- }
- else
- {
- ob.x = (ob.xtile + 1) * game.tileW - ob.width;
- }
- }
- ob.clip._x = ob.x;
- ob.clip._y = ob.y;
- ob.clip.gotoAndStop(dirx + diry * 2 + 3);
- ob.xtile = Math.floor(ob.clip._x / game.tileW);
- ob.ytile = Math.floor(ob.clip._y / game.tileH);
- var itemname = game["item" + ob.ytile + "_" + ob.xtile];
- if(itemname and ob == _root.char)
- {
- game.points = true;
- removeMovieClip(itemname.clip);
- game.items[itemname.position] = 0;
- delete game["item" + ob.ytile + "_" + ob.xtile];
- var name = "enemy3";
- game[name] = new game.Enemyp3();
- game.clip.attachMovie("enemy1",name,10005);
- game[name].clip = game.clip[name];
- game[name].xtile = 4;
- game[name].ytile = 2;
- game[name].width = game.clip[name]._width / 2;
- game[name].height = game.clip[name]._height / 2;
- game[name].x = game[name].xtile * game.tileW + game.tileW / 2;
- game[name].y = game[name].ytile * game.tileH + game.tileH / 2;
- game[name].clip._x = game[name].x;
- game[name].clip._y = game[name].y;
- if(game.points = true)
- {
- opendoorname = "t_" + unlockY + "_" + unlockX;
- game.clip[opendoorname].gotoAndStop(4);
- game.Tile2.prototype.walkable = true;
- }
- }
- if(_root.char.ytile == unlockY && _root.char.xtile == unlockX)
- {
- removeMovieClip(_root.tiles);
- _root.gotoAndStop(11);
- }
- if(_root.char.ytile == 4 && _root.char.xtile == 4)
- {
- var name = "enemy3";
- game[name].xMove = 0;
- game[name].yMove = -1;
- game[name].speed = 0.5;
- }
- return true;
- }
- function getMyCorners(x, y, ob)
- {
- ob.downY = Math.floor((y + ob.height - 1) / game.tileH);
- ob.upY = Math.floor((y - ob.height) / game.tileH);
- ob.leftX = Math.floor((x - ob.width) / game.tileW);
- ob.rightX = Math.floor((x + ob.width - 1) / game.tileW);
- ob.upleft = game["t_" + ob.upY + "_" + ob.leftX].walkable;
- ob.downleft = game["t_" + ob.downY + "_" + ob.leftX].walkable;
- ob.upright = game["t_" + ob.upY + "_" + ob.rightX].walkable;
- ob.downright = game["t_" + ob.downY + "_" + ob.rightX].walkable;
- }
- fscommand("allowscale",true);
- myMap1 = [[5,5,5,5,1,5,5,5,5,5],[5,5,5,1,2,1,5,5,5,5],[5,5,1,0,0,0,1,5,5,5],[5,5,5,1,0,1,1,1,1,5],[5,5,1,0,0,0,0,0,0,1],[5,5,5,1,0,1,1,0,1,5],[5,5,5,1,0,1,5,1,5,5],[5,5,1,0,0,1,5,5,5,5],[5,5,5,1,1,5,5,5,5,5]];
- game = {tileW:45,tileH:45,currentMap:1,points:false};
- game.Tile0 = function()
- {
- };
- game.Tile0.prototype.walkable = true;
- game.Tile0.prototype.frame = 1;
- game.Tile1 = function()
- {
- };
- game.Tile1.prototype.walkable = false;
- game.Tile1.prototype.frame = 2;
- game.Tile2 = function()
- {
- };
- game.Tile2.prototype.walkable = false;
- game.Tile2.prototype.frame = 3;
- game.Tile5 = function()
- {
- };
- game.Tile5.prototype.walkable = false;
- game.Tile5.prototype.frame = 5;
- unlockY = 1;
- unlockX = 4;
- char = {xtile:3,ytile:7,speed:3};
- startingXtile = char.xtile;
- startingYtile = char.ytile;
- mylifes.gotoAndStop(_root.lifes);
- myEnemies = [[1,3,4],[2,4,2]];
- game.Enemyp1 = function()
- {
- };
- game.Enemyp1.prototype.xMove = 1;
- game.Enemyp1.prototype.yMove = 0;
- game.Enemyp1.prototype.speed = 1;
- game.Enemyp2 = function()
- {
- };
- game.Enemyp2.prototype.xMove = 1;
- game.Enemyp2.prototype.yMove = 0;
- game.Enemyp2.prototype.speed = 1;
- game.Enemyp3 = function()
- {
- };
- game.Enemyp3.prototype.xMove = 0;
- game.Enemyp3.prototype.yMove = 1;
- game.Enemyp3.prototype.speed = 1;
- myItems = [[1,7,5]];
- game.Item1 = function()
- {
- };
- game.Item1.prototype.points = false;
- _root.buildMap(_root["myMap" + game.currentMap]);
- stop();
-